package io.nanfeng.generic

import Doctor
import Person
import Teacher

interface A<T : Person>
interface B<T : Person> : A<T>
interface C<T : Teacher> : A<T>


fun <T> test(): T? where T : Person {
    return null
}

fun <T> test1(): T? where T : Teacher {
    return null
}

fun <T> test2(): T? where T : Doctor {
    return null
}


fun testStar() {
    val map: MutableMap<in Number, out Any> = mutableMapOf()
    // 应为V 为out 所以只能读
    //Type mismatch.
    //Required:  CapturedType(out Any)
    //Found: String
    //map["sample"] = "sample"
    val values: MutableCollection<out Any> = map.values
    val keys: MutableSet<in Number> = map.keys
    keys.add(1)
    keys.add(1.0)

}

class Test<out T:Number>{
    fun set(t: @UnsafeVariance T){

    }
    fun get():T?{
        return null
    }
}
class Test1<in T:Number>{
    fun set(t:  T){

    }
    fun get(): @UnsafeVariance T?{
        return null
    }
}

class Test3<T : Number>{
    fun set(t:  T){

    }
    fun get():  T?{
        return null
    }
}
fun testStar1() {
    val test: Test<*> = Test<Int>()
    test.set(1)
    val get: Number? = test.get()
    val test1: Test1<*> = Test1<Int>()
//    The integer literal does not conform to the expected type Nothing
//    test1.set(1)
    val number: Number? = test1.get()
    val test3: Test3<*> = Test3<Int>()
//    //    The integer literal does not conform to the expected type Nothing
//    test3.set(1)
    val get3: Number? = test3.get()
}